package com.longge.wechat.thread;

public class ThreadTest {
	private static int num = 0;

	private ThreadTest() {}
	
	public synchronized static int getIndex() {
		if(num < 20) {
			num ++;
		}
		return num;
	}
	
	public static void main(String[] args) {
		for (int i = 0; i < 10000; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					//new ThreadTest().getIndex()++;
					System.out.println(new ThreadTest().getIndex());
				}
			}).start();
		}
	}
}
